extends layout

block content
  if account.isContract
    h3 Contract #{account.address}
  else
    h3 Account #{account.address}
  table.table
    tr
      td Balance:
      td #{ethformatter(account.balance)}
    if account.name
      tr
        td Name:
        td #{account.name}

  div
    ul.nav.nav-tabs(role='tablist')
      li.active(role='presentation')
        a(href='#transactions', aria-controls='transactions', role='tab', data-toggle='tab') Transactions
      if account.isContract
        li(role='presentation')
          a(href='#code', aria-controls='code', role='tab', data-toggle='tab') Code
      if account.source
        li(role='presentation')
          a(href='#source', aria-controls='source', role='tab', data-toggle='tab') Source
        li(role='presentation')
          a(href='#contractState', aria-controls='source', role='tab', data-toggle='tab') Contract State
    .tab-content
      #transactions.tab-pane.active(role='tabpanel')
        h3 Recent Activity
        table.table
          thead
            tr
              th Hash
              th Block
              th Type
              th
              th From
              th To
              th Amount
          tbody
            for block in account.blocks
              for trace in block
                if trace.type === "reward" && trace.action.author === account.address
                  tr
                    td
                      a(href="/block/" + trace.blockNumber) #{trace.blockHash.substr(0, 10)}...
                    td
                      a(href="/block/" + trace.blockNumber) #{trace.blockNumber}
                    td Mining Reward
                    td
                    td New Coins
                    td 
                      a(href="/account/" + trace.action.author) #{nameformatter.format(trace.action.author)}
                    td #{ethformatter(trace.action.value)}
                else if trace.type !== "reward"
                  tr            
                    td 
                      a(href="/tx/" + trace.transactionHash)  #{trace.transactionHash.substr(0, 10)}...
                    td
                      a(href="/block/" + trace.blockNumber) #{trace.blockNumber}
                    td.capitalize
                      if trace.error
                        span(style="color: red", data-toggle="tooltip", data-placement="left", title=trace.error).glyphicon.glyphicon-warning-sign
                      |  #{trace.type}
                    if trace.type === "call"
                      td
                        if trace.action.from === account.address
                          span.glyphicon.glyphicon-export(style="color: red;")
                        else
                          span.glyphicon.glyphicon-import(style="color: green;")
                      td
                        a(href="/account/" + trace.action.from) #{nameformatter.format(trace.action.from)}
                      td 
                        a(href="/account/" + trace.action.to) #{nameformatter.format(trace.action.to)}
                      td #{ethformatter(trace.action.value)}
                    else if trace.type === "create"
                      td
                        if trace.action.from === account.address
                          span.glyphicon.glyphicon-export(style="color: red;")
                        else
                          span.glyphicon.glyphicon-import(style="color: green;")
                      td
                        a(href="/account/" + trace.action.from) #{nameformatter.format(trace.action.from)}
                      td
                        a(href="/account/" + trace.result.address) #{nameformatter.format(trace.result.address)}
                      td #{ethformatter(trace.action.value)}
                    else if trace.type === "suicide"
                      td
                        if trace.action.address === account.address
                          span.glyphicon.glyphicon-export(style="color: red;")
                        else
                          span.glyphicon.glyphicon-import(style="color: green;")
                      td
                        a(href="/account/" + trace.action.address) #{nameformatter.format(trace.action.address)}
                      td
                        a(href="/account/" + trace.action.refundAddress) #{nameformatter.format(trace.action.refundAddress)}
                      td #{ethformatter(trace.action.balance)}
      
      if account.isContract
        #code.tab-pane(role='tabpanel')
          h3 Code
          if !account.source
            a(href="/contract/verify") Upload source
          pre #{account.code}
      if account.source
        #source.tab-pane(role='tabpanel')
          h4 Source
          pre #{account.source.source}
          h4 ABI
          pre #{account.source.abi}
          h4 Constructor
          pre #{account.source.constructorArgs}
        #contractState.tab-pane(role='tabpanel')
          h4 Current contract state
          table.table
            thead
              tr
                th Function
                th Result
            tbody
              for item in account.contractState
                tr
                  td #{item.name}
                  td #{item.result}